<script>
$(function(){
	$('#profile').validate({
		rules:{
			currentPassword:{
					required: true,
					minlength: 6
			},
			newPassword:{
				required: true,
				minlength: 6
			},
			confirmPassword:{
				required: true,
				equalTo: '#newPassword'
			}
		},
		messages:{
			currentPassword: {
				required: "This field is required",
				minlength: 'Password should be minimum of 6 characters'
			},
			newPassword: {
				required: "This field is required",
				minlength: 'Password should be minimum of 6 characters'
			},
			confirmPassword: {
				required: "You should confirm the new password",
				equalTo: "Confirm password failed."
			} 
		}
	});
});
</script>
<?php
	if(isset($_SESSION['userTypeId']) && ($_SESSION['userTypeId'] == "1" || $_SESSION['userTypeId'] == "2" || $_SESSION['userTypeId'] == "3" ))
		//include './pages/adminMenu.php'; 
?>

<div class="mainContent">
	<div class="masterData">
	<?php 
	if(isset($_SESSION['userTypeId']) && ($_SESSION['userTypeId'] > "2")){
	?>
		<h3>My Profile</h3>
		<?php
	}
			$userName = $_SESSION['userName'];
			include('./system/dbConnection.php');
			if($result=mysql_query("SELECT * FROM users WHERE userName = '$userName'")){
				if($row = mysql_fetch_array($result)){
					if($_SESSION['userTypeId'] > "2"){
						echo "<table border='1' cellspacing='0' width='100%' class='masterTable'>";
						echo "<tr><td width='40%'><b>Full Name</b></td><td>&nbsp;&nbsp;".$row['userFullName']."</td></tr>";
						echo "<tr><td width='40%'><b>Address</b></td><td>&nbsp;&nbsp;".$row['userAddress']."</td></tr>";
						if($row['userTelephone'])
							echo "<tr><td width='40%'><b>Telephone</b></td><td>&nbsp;&nbsp;".$row['userTelephone']."</td></tr>";
						echo "<tr><td width='40%'><b>Reg. Date</b></td><td>&nbsp;&nbsp;".$row['userRegistrationDate']."</td></tr>";
						echo "<tr><td width='40%'><b>Last Log Date</b></td><td>&nbsp;&nbsp;".$row['lastLogDate']."</td></tr>";
						echo "</table>";	
					}
				}else{
					if(isset($_SESSION['userTypeId']) && ($_SESSION['userTypeId'] > "2"))
						echo "No Data in Database";
				}	
			}
		?>
	</div>
	<div class="mainForm">
	<?php 
	if(isset($_SESSION['userTypeId']) && ($_SESSION['userTypeId'] > "2")){
	?>
		<h4>Change Password</h4>
	<?php
	}else{
	?>
		<h4>Change Details</h4>
	<?php
	}
	?>
		<form action="./system/action/profile.php" method="post" name="profile" id="profile">
			<table>
				<tr>
					<td colspan='2px'>
						<?php
						if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ ?>
							<div class="error">
								<?php echo $_SESSION['error']; ?>
							</div>
						<?php } else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){?>
							<div class="success">
								<?php echo $_SESSION['success']; ?>
							</div>
						<?php }?>					
					</td>
				</tr>
				<?php
				if(isset($_SESSION['userTypeId']) && ($_SESSION['userTypeId'] <= "2" )){
				?>
					<tr>
						<td align="left" width="50%">Full Name</td>
						<td><input type = "text" name = "userFullName" class="width_200" id = "userFullName" value="<?php echo $row['userFullName']; ?>"></td>
					</tr>
					<tr>
						<td align="left" width="50%">Address </td>
						<td><input type = "text" name = "userAddress" class="width_200" id = "userAddress" value="<?php echo $row['userAddress']; ?>"></td>
					</tr>
					<tr>
						<td align="left" width="50%">Telephone </td>
						<td><input type = "text" name = "userTelephone" class="width_200" id = "userTelephone" value="<?php echo $row['userTelephone']; ?>"></td>
					</tr>
				<?php
				}
				?>
				<tr>
					<td align="left" width="50%">Current PassWord</td>
					<td><input type = "password" name = "currentPassword" class="width_200" id = "currentPassword"></td>
				</tr>
				<tr>
					<td align="left" width="50%">New PassWord</td>
					<td><input type = "password" name = "newPassword" class="width_200" id = "newPassword"></td>
				</tr>
				<tr>
					<td align="left" width="50%">Confirm Password</td>
					<td><input type = "password" name = "confirmPassword" class="width_200" id = "confirmPassword"></td>
				</tr>
				<tr><td></td><td><input type = "submit" value = "Save" name = "submitPassword"></td></tr>
			</table>
		</form>	
	</div>
</div>